CSharpTest.Net
DisposingList<T> Constructor(IEnumerable<T>)
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > DisposingList<T> Class > DisposingList<T> Constructor : DisposingList<T> Constructor(IEnumerable<T>)

collection

Glossary Item Box

Initializes a new instance of the System.Collections.Generic.List>T> class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied.

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal collection As IEnumerable(Of T) _
)
C# 
public DisposingList<T>( 
   IEnumerable<T> collection
)

Parameters

collection

Example

Library/Library.Test/TestDisposingList.cs

C#Copy Code
disposeOrder.Clear();
DisposingList<DisposeInOrder> list = new DisposingList<DisposeInOrder>();

DisposeInOrder a = new DisposeInOrder();
DisposeInOrder b = new DisposeInOrder();

list.Add(a);
list.Add(b);
list.Add(null);
list.Dispose();

//Removed from list?
Assert.AreEqual(0, list.Count);
//All were disposed?
Assert.AreEqual(2, disposeOrder.Count);
//Disposed in reverse order of creation?
Assert.IsTrue(object.ReferenceEquals(b, disposeOrder[0]));
Assert.IsTrue(object.ReferenceEquals(a, disposeOrder[1]));

Assert.AreEqual(2, new DisposingList<DisposeInOrder>(new DisposeInOrder[] { a, b }).Count);
Assert.AreEqual(0, new DisposingList<DisposeInOrder>(5).Count);
VB.NETCopy Code
disposeOrder.Clear()
Dim list As New DisposingList(Of DisposeInOrder)()

Dim a As New DisposeInOrder()
Dim b As New DisposeInOrder()

list.Add(a)
list.Add(b)
list.Add(Nothing)
list.Dispose()

'Removed from list?
Assert.AreEqual(0, list.Count)
'All were disposed?
Assert.AreEqual(2, disposeOrder.Count)
'Disposed in reverse order of creation?
Assert.IsTrue(Object.ReferenceEquals(b, disposeOrder(0)))
Assert.IsTrue(Object.ReferenceEquals(a, disposeOrder(1)))

Assert.AreEqual(2, New DisposingList(Of DisposeInOrder)(New DisposeInOrder() {a, b}).Count)
Assert.AreEqual(0, New DisposingList(Of DisposeInOrder)(5).Count)

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys